package com.cyd.product_service.cluster.loadbalance;

import com.cyd.product_service.cluster.ClusterService;
import com.cyd.product_service.cluster.LoadBalance;

import java.util.List;
import java.util.Random;


/**
 * 简单随机负载均衡
 * Created by fangzhihong on 2017/11/24.
 */
public class SimpleRandomLoadBalance implements LoadBalance {

    private Random random = new Random();

    @Override
    public ClusterService select(List<ClusterService> services) {
        if (services.size() == 1) {
            return services.get(0);
        }
        return services.get(random.nextInt(services.size()));
    }
}
